using System;
using System.Data.Entity.ModelConfiguration;
using System.Data.Common;
using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using HISModels.Entities;

namespace HISModels.Mapping
{
	public class BillDetailMap : EntityTypeConfiguration<BillDetail>
	{
		public BillDetailMap()
		{
			// Primary Key
			this.HasKey(t => t.Id);

			// Properties
			this.Property(t => t.CodeValue)
				.HasMaxLength(50);
				
			this.Property(t => t.CorporatePayerId)
				.IsFixedLength()
				.HasMaxLength(10);
				
			// Table & Column Mappings
			this.ToTable("BillDetails");
			this.Property(t => t.Id).HasColumnName("Id");
			this.Property(t => t.BillId).HasColumnName("BillId");
			this.Property(t => t.GSCSlipBillRelId).HasColumnName("GSCSlipBillRelId");
			this.Property(t => t.CodeValue).HasColumnName("CodeValue");
			this.Property(t => t.Remark).HasColumnName("Remark");
			this.Property(t => t.TermOfPayment).HasColumnName("TermOfPayment");
			this.Property(t => t.CorporatePayerId).HasColumnName("CorporatePayerId");

			// Relationships
			this.HasOptional(t => t.Bill)
				.WithMany(t => t.BillDetails)
				.HasForeignKey(d => d.BillId);
				
			this.HasOptional(t => t.GSCSBillRel)
				.WithMany(t => t.BillDetails)
				.HasForeignKey(d => d.GSCSlipBillRelId);
				
		}
	}
}

